getUserInfo();
function getUserInfo(){
    $.ajax({
        url:config.url + "/getUserInfo",
        dataType:'json',
        xhrFields: {
            withCredentials: true
        },
        headers:{
            "token":localStorage.getItem("token")
        },
        crossDomain: true,
        type:'GET' ,
        success:function(resp) {
            if(resp.data != null){
                $("#login-reg-btn")[0].innerHTML = "欢迎 " + resp.data;
            }else{
                $("#login-reg-btn")[0].innerHTML = "登录/注册";
            }
        },
        error:function() {
        }
    });
}

//咨询师推荐

queryBtn();
function queryBtn(){
    console.log(localStorage.getItem("token"));
    $.ajax({
        headers:{
            "token":localStorage.getItem("token")
        },
        url:config.url + "/getConsInfoByIndex",
        dataType:'json',
        xhrFields: {
            withCredentials: true
        },
        data:{
        },
        crossDomain: true,
        type:'get',
        success:function(resp) {
            arr = resp.data;
            renderConsIntro(arr);

        },
        error:function() {
        }
    });
}

function renderConsIntro(arr){
    let str = '';
    console.log(arr);
    for (let i = 0; i < arr.length ; i++) {
        let a  = arr[i].consultantFieldVos;
        let b  = arr[i];
        let field = "";

        for (let j = 0; j < a.length; j++) {
            field += a[j].fieldName + "&nbsp;"
        }
        str += `<div class="cons-item">
                    <div class="img"><img src="img/index/cons${i}.JPG" style="width: 200px;height: 209px"></div>
                    <div class="intro">
                        <div><span>姓名: </span>${b.name}</div>
                        <div><span>职称: </span>${b.positionalTitles}</div>
                        <div><span>擅长领域: </span>${field}</div>
                    </div>
                    <div class="btn-wrapper">
                        <button class="btn btn-success searchBtn btn-lg btn-primary" 
                                    type="button" href="main.html"><a href="main.html" style="color: white;text-decoration:none;">
                                    点击查看详情</a></button>
                    </div>
                </div>`;
        $('#cons-wrap1')[0].innerHTML = str;
    }
}
abc();
function abc(){
    let nav = $('.nav-wrap');

    console.log(nav.offset().top) // 得到0
    scrollTo(20, 100);
    console.log(window.of);

    $(window).scroll(function () {
        //获取滚动条的高度
        var scrollTop = $(this).scrollTop();
        //获取一个屏幕的高度

        // var windowHeight = document.body.clientHeight;
        //
        // console.log("div本身的高度:" + nav.height());
        //
        // console.log("距离顶部的的位置" + scrollTop);

        //当滚动条滚动到一边的最底部，把需要的div滚动到底部就固定div不让移动了

        if (scrollTop >= 150){
            console.log(111)
                console.log(scrollTop)
                nav.css("position", "fixed"); //固定div让其不随着滚动条的滚动而滚动
                nav.css("z-index","10000")
                nav.css("top", "0");
                nav.css("margin", "0");
        }
        else{
            nav.css("position", "");
        }
        // if (scrollTop >= nav.height()) {
        //     console.log(scrollTop)
        //     nav.css("position", "fixed"); //固定div让其不随着滚动条的滚动而滚动
        //     nav.css("z-index","10000")
        //     nav.css("top", "0");
        // }else{
        //     nav.css("position", "fixed"); //固定div让其不随着滚动条的滚动而滚动
        //     nav.css("z-index","10000")
        //     nav.css("top", "100");
        // }

    })
}

